package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

import javax.swing.*;

import org.come.Frame.ZhuFrame;
import org.come.bean.GoodTrans;
import org.come.bean.GoodTrans2;
import org.come.entity.Goodstable;
import org.come.entity.RoleSummoning;
import org.come.model.Lingbao;
import org.come.mouslisten.PetAddPointOneMouslisten;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.*;

import com.tool.Document.InputNum;
import com.tool.Document.NumberDocument;
import com.tool.PanelDisplay.PetPanelShow;
import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.TransBtn;
import com.tool.btn.goodbtn;
import com.tool.role.RoleData;
import com.tool.role.RoleLingFa;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



public class TransJpanel extends JPanel implements InputNum {

    // 放置6个背包切换按钮
    private goodbtn[] btnrights;
    private transRole myTransRole;
    private transRole noTransRole;
    // private
    private JLabel[] GoodsListLabel = null;// 用来存放24个物品表格
    private TransBtn petBtn;// 召唤兽
    private TransBtn lingBtn;// 灵宝
    private TransBtn queBtn;// 确定

    private int jpanelType = 0;// 显示的面板
    // 召唤兽列表
    private JList<String> listpet;
    // 列表中的对象
    private DefaultListModel<String> listModel;// 放置召唤兽的对象
    // 滚动条
    private JScrollPane jScrollPane;

    public JLabel[] lingsLabel = null;// 用来存放9个灵宝表格
    private TransBtn upBtn;// 上一页
    private TransBtn downBtn;// 下一页
    private int ys = 0;

    public TransJpanel() throws Exception {
    		this.setPreferredSize(new Dimension(558, 470));
            this.setBackground(UIUtils.Color_BACK);
            this.setLayout(null);
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 14);
            offBtn.setBounds(558 - 37, 10, 25, 25);
            this.add(offBtn);
            // 加锁按钮
            queBtn = new TransBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "确定", 2, this);
            queBtn.setBounds(20 + 23, 285 - 13, 59, 24);
            this.add(queBtn);
            // 63 26
            petBtn = new TransBtn("skin/8100226/button/B150.png", 1, 0, this);
            petBtn.setBounds(22 + 28, 20 - 15, 63, 26);
            this.add(petBtn);
            lingBtn = new TransBtn("skin/8100226/button/B137.png", 1, 1, this);
            lingBtn.setBounds(87 + 28, 20 - 15, 63, 26);
            this.add(lingBtn);
            init();
    }

    public void init() {
    		btnrights = new goodbtn[6];
            for (int i = 0; i < btnrights.length; i++) {
                btnrights[i] = new goodbtn("skin/8100226/newbutton/C0"+(i+1)+".png", 0, this, i);
                btnrights[i].setBounds(523, 30 + i * 35, 39, 31);
                this.add(btnrights[i]);
            }
            GoodsListLabel = new JLabel[24];
            // 存放物品的表格1~24
            for (int i = 0; i < 24; i++) {
                GoodsListLabel[i] = new JLabel();
                GoodsListLabel[i].setBounds(217 + i % 6 * 51, 34 + i / 6 * 51, 49, 49);
                GoodsListLabel[i].addMouseListener(new transMouse(i, -1));
                this.add(GoodsListLabel[i]);
            }
            lingsLabel = new JLabel[9];
            for (int i = 0; i < 9; i++) {
                lingsLabel[i] = new JLabel();
                lingsLabel[i].setBounds(51 + i % 3 * 51, 35 + i / 3 * 51, 49, 49);
                lingsLabel[i].addMouseListener(new transMouse(i, -2));
                lingsLabel[i].setVisible(false);
                this.add(lingsLabel[i]);
            }
            upBtn = new TransBtn("skin/8100226/button/10.png", 1, 3, this);
            upBtn.setBounds(140 + 24, 200 - 13, 18, 18);
            upBtn.setVisible(false);
            this.add(upBtn);
            downBtn = new TransBtn("skin/8100226/button/9.png", 1, 4, this);
            downBtn.setBounds(160 + 24, 200 - 13, 18, 18);
            downBtn.setVisible(false);
            this.add(downBtn);

            listModel = new DefaultListModel<String>();
            // 召唤兽列表
            listpet = new JList<String>();
            listpet.setOpaque(false);
            listpet.setSelectionBackground(new Color(33, 42, 52));
            listpet.setSelectionForeground(Color.GREEN);
            listpet.setForeground(Color.GREEN);
            listpet.setFont(new Font("微软雅黑", 1, 14));
            listpet.setBackground(UIUtils.Color_BACK); // 设置列表框为透明背景
            listpet.setModel(listModel);
            listpet.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            listpet.addMouseListener(new transPetMouse());

            // 召唤兽列表滚动条
            jScrollPane = new JScrollPane(listpet);
            jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            jScrollPane.getVerticalScrollBar().setUI(new SrcollPanelUI());
            jScrollPane.getViewport().setOpaque(false);
            jScrollPane.setOpaque(false);
            jScrollPane.setBounds(49, 52, 159, 157);
            jScrollPane.setBorder(null);
            jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            this.add(jScrollPane);

    }

    /** 重置交易 */
    public void transReset(BigDecimal role_id, String roleName) {
        if (myTransRole == null) {
            myTransRole = new transRole(this);
        }
        if (noTransRole == null) {
            noTransRole = new transRole(role_id, roleName);
        }
        myTransRole.reset(null, null);
        noTransRole.reset(role_id, roleName);
        listModel.clear();
        if (UserMessUntil.getPetListTable() != null) {
            for (int i = 0; i < UserMessUntil.getPetListTable().size(); i++) {
                listModel.addElement(UserMessUntil.getPetListTable().get(i).getSummoningname());
            }
        }
        ys = 0;
        cJpanelType(0);
        FormsManagement.showForm(14);
    }

    /** 界面切换 */
    public void cJpanelType(int p) {
    		if (jpanelType == p) {
                return;
            }
            jpanelType = p;
            boolean is = jpanelType == 0;
            jScrollPane.setVisible(is);
            is = !is;
            for (int i = 0; i < lingsLabel.length; i++) {
                lingsLabel[i].setVisible(is);
            }
            upBtn.setVisible(is);
            downBtn.setVisible(is);
            try {
                if (is) {
                    petBtn.setIcons(CutButtonImage.cuts("skin/8100226/button/B149.png"));
                    lingBtn.setIcons(CutButtonImage.cuts("skin/8100226/button/B138.png"));
                } else {
                    petBtn.setIcons(CutButtonImage.cuts("skin/8100226/button/B150.png"));
                    lingBtn.setIcons(CutButtonImage.cuts("skin/8100226/button/B137.png"));
                }
            } catch (Exception e) {
                // TODO: handle exception
            }
    }

    class transRole {
        private int type;
        private BigDecimal role_id;
        private String roleName;
        private String MSG = "已确定";
        private JTextField field;
        private JLabel[] jLabels;// 0-23 24-25 26-27
        private GoodTrans goodTrans;

        public transRole(TransJpanel transJpanel) {
        		// TODO Auto-generated constructor stub
                field = new JTextField();
                field.setBounds(86, 243, 121, 16);
                field.setBorder(null);
                field.setOpaque(false);
                field.setCaretColor(Color.white);
                field.setForeground(Color.white);
                field.setFont(UIUtils.TEXT_FONT1);
                field.setDocument(new NumberDocument(field, 0, transJpanel));
                add(field);
                jLabels = new JLabel[13];
                for (int i = 0; i < 8; i++) {
                    jLabels[i] = new JLabel();
                    jLabels[i].setBounds(20 + 23 + i % 4 * 51, 357 - 13 + i / 4 * 51, 49, 49);
                    jLabels[i].addMouseListener(new transMouse(i, 0));
                    add(jLabels[i]);
                }
                for (int i = 0; i < 4; i++) {
                    int p = i + 8;
                    jLabels[p] = new JLabel();
                    jLabels[p].setBounds(20 + 23 + i / 2 * 110, 310 - 13 + i % 2 * 20, 95, 18);
                    jLabels[p].addMouseListener(new transMouse(p, 0));
                    add(jLabels[p]);
                }
                jLabels[12] = new JLabel();
                jLabels[12].setBounds(140, 270, 15, 15);
                jLabels[12].addMouseListener(new transMouse(12, 0));
                add(jLabels[12]);
        }

        public transRole(BigDecimal role_id, String roleName) {
        		// TODO Auto-generated constructor stub
                this.role_id = role_id;
                this.roleName = roleName;
                field = new JTextField();
                field.setBounds(376, 247, 121, 16);
                field.setBorder(null);
                field.setOpaque(false);
                field.setEditable(false);
                field.setText("0");
                field.setForeground(Color.white);
                field.setFont(UIUtils.TEXT_FONT1);
                field.setDocument(new NumberDocument(field, 4));
                add(field);
                jLabels = new JLabel[13];
                for (int i = 0; i < 8; i++) {
                    jLabels[i] = new JLabel();
                    jLabels[i].setBounds(290 + i % 4 * 51, 357 + i / 4 * 51, 49, 49);
                    jLabels[i].addMouseListener(new transMouse(i, 1));
                    add(jLabels[i]);
                }
                for (int i = 0; i < 4; i++) {
                    int p = i + 8;
                    jLabels[p] = new JLabel();
                    jLabels[p].setBounds(290 + i / 2 * 110, 310 + i % 2 * 20, 95, 18);
                    jLabels[p].addMouseListener(new transMouse(p, 1));
                    add(jLabels[p]);
                }
                jLabels[12] = new JLabel();
                jLabels[12].setBounds(503, 248, 15, 15);
                add(jLabels[12]);
        }

        /** 重置 */
        public void reset(BigDecimal role_id, String roleName) {
            this.role_id = role_id;
            this.roleName = roleName;
            this.goodTrans = new GoodTrans();
            setType(0);
            this.field.setText("0");
        }

        protected void paint(Graphics g) {
        		if (roleName != null) {
                    g.setColor(Color.red);
                    g.drawString(roleName, 290 + 23, 303 - 13);
                    if (goodTrans != null) {
                        goodTrans.paint(g, 1);
                    }
                    if (MSG != null) {
                        g.setColor(Color.RED);
                        g.drawString(MSG, 450 + 23, 303 - 13);
                    }
                } else {
                    g.setColor(Color.white);
                    if (goodTrans != null) {
                        goodTrans.paint(g, 0);
                    }
                    if (MSG != null) {
                        g.setColor(Color.RED);
                        g.drawString(MSG, 160, 280);
                    }
                }
        }

        public void setType(int type) {
        		this.type = type;
                if (this.type == 0) {
                    MSG = null;
                    jLabels[12].setIcon(null);
                } else if (this.type == 1) {
                    MSG = "未确定";
                    jLabels[12].setIcon(CutButtonImage.getImage("skin/8100226/button/B88.png", -1, -1));
                } else if (this.type == 2) {
                    MSG = "已确定";
                    jLabels[12].setIcon(CutButtonImage.getImage("skin/8100226/button/B88.png", -1, -1));
                }
        }
    }

    class transMouse implements MouseListener {
        private int p;
        // -1物品24格监听
        private int type;

        public transMouse(int p, int type) {
            super();
            this.p = p;
            this.type = type;
        }

        @Override
        public void mouseClicked(MouseEvent e) {

        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (type == 0 && p == 12) {
                if (myTransRole.jLabels[12].getIcon() == null) {
                    String send = Agreement.getAgreement().TransStateAgreement("3");
                    SendMessageUntil.toServer(send);
                } else {
                    String send = Agreement.getAgreement().TransStateAgreement("4");
                    SendMessageUntil.toServer(send);
                }
                return;
            }
            if (myTransRole.type != 0) {
                return;
            }
            if (type == -2) {
                if (myTransRole.goodTrans.getLingbaos() != null && myTransRole.goodTrans.getLingbaos().size() >= 2) {
                    ZhuFrame.getZhuJpanel().addPrompt2("格子已满");
                    return;
                }
                if (myTransRole.type != 0) {
                    ZhuFrame.getZhuJpanel().addPrompt2("你已锁定");
                    return;
                }
                Lingbao lingbao = RoleLingFa.getRoleLingFa().getTrans(ys, myTransRole.goodTrans.getLingbaos(), p);
                if (lingbao != null) {
                    myTransRole.goodTrans.setLingbao(lingbao, true);
                    GoodTrans2 goodTrans2 = new GoodTrans2();
                    goodTrans2.setI(true);
                    goodTrans2.setLingbao(lingbao);
                    String send = Agreement.getAgreement().TransGoodAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
                    SendMessageUntil.toServer(send);
                }
            } else if (type == -1) {
                Goodstable goodstable = GoodsListFromServerUntil.Getgood(p);
                if (goodstable != null) {
                    if (GoodsListFromServerUntil.isJY(goodstable)) {
                        ZhuFrame.getZhuJpanel().addPrompt2("该物品禁止交易");
                        return;
                    }
                    if (myTransRole.goodTrans.getGoods() != null && myTransRole.goodTrans.getGoods().size() >= 8) {
                        ZhuFrame.getZhuJpanel().addPrompt2("格子已满");
                        return;
                    }
                    if (myTransRole.type != 0) {
                        ZhuFrame.getZhuJpanel().addPrompt2("你已锁定");
                        return;
                    }
                    Goodstable good = myTransRole.goodTrans.getGood(goodstable.getRgid());
                    if (good == null) {
                        good = (Goodstable) goodstable.clone();
                        good.setUsetime(1);
                        myTransRole.goodTrans.setGood(good);
                    } else {
                        good.setUsetime(good.getUsetime() + 1);
                    }
                    goodstable.goodxh(1);
                    if (goodstable.getUsetime() <= 0) {
                        GoodsListFromServerUntil.Deletebiaoid(goodstable.getRgid());
                    }
                    GoodTrans2 goodTrans2 = new GoodTrans2();
                    goodTrans2.setI(true);
                    goodTrans2.setGoods(good);
                    String send = Agreement.getAgreement().TransGoodAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
                    SendMessageUntil.toServer(send);
                }
            } else if (type == 0) {
                if (myTransRole.type != 0) {
                    ZhuFrame.getZhuJpanel().addPrompt2("你已锁定");
                    return;
                }
                if (p < 8) {
                    Goodstable goodstable = myTransRole.goodTrans.getGood(p);
                    if (goodstable != null) {
                        Goodstable good = (Goodstable) goodstable.clone();
                        goodstable.setUsetime(0);
                        myTransRole.goodTrans.getGoods().remove(goodstable);
                        GoodTrans2 goodTrans2 = new GoodTrans2();
                        goodTrans2.setI(false);
                        goodTrans2.setGoods(goodstable);
                        String send = Agreement.getAgreement().TransGoodAgreement(
                                GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
                        SendMessageUntil.toServer(send);
                        GoodsListFromServerUntil.stall2(good);

                    }
                } else if (p < 10) {
                    RoleSummoning pet = myTransRole.goodTrans.getPet(p - 8);
                    if (pet != null) {
                        UserMessUntil.getPetListTable().add(pet);
                        listModel.addElement(pet.getSummoningname());
                        myTransRole.goodTrans.setPet(pet, false);
                        GoodTrans2 goodTrans2 = new GoodTrans2();
                        goodTrans2.setI(false);
                        goodTrans2.setPet(pet);
                        String send = Agreement.getAgreement().TransGoodAgreement(
                                GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
                        SendMessageUntil.toServer(send);
                    }
                } else if (p < 12) {
                    Lingbao lingbao = myTransRole.goodTrans.getLingbao(p - 10);
                    if (lingbao != null) {
                        myTransRole.goodTrans.getLingbaos().remove(lingbao);
                        GoodTrans2 goodTrans2 = new GoodTrans2();
                        goodTrans2.setI(false);
                        goodTrans2.setLingbao(lingbao);
                        String send = Agreement.getAgreement().TransGoodAgreement(
                                GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
                        SendMessageUntil.toServer(send);
                    }
                }
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            if (type == -2) {
                Lingbao lingbao = RoleLingFa.getRoleLingFa().getTrans(ys, myTransRole.goodTrans.getLingbaos(), p);
                if (lingbao != null) {
                    ZhuFrame.getZhuJpanel().creatlingtext(lingbao);
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                }
            } else if (type == -1) {
                Goodstable goodstable = GoodsListFromServerUntil.Getgood(p);
                if (goodstable != null) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }
            } else {
                transRole role = null;
                if (type == 0) {
                    role = myTransRole;
                } else {
                    role = noTransRole;
                }
                if (role == null) {
                    return;
                }
                if (p < 8) {
                    Goodstable goodstable = role.goodTrans.getGood(p);
                    if (goodstable != null) {
                        ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                    }
                } else if (p < 10) {
                    RoleSummoning pet = role.goodTrans.getPet(p - 8);
                    if (pet != null) {
                        ZhuFrame.getZhuJpanel().creatpettext(pet);
                        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                    }
                } else if (p < 12) {
                    Lingbao lingbao = role.goodTrans.getLingbao(p - 10);
                    if (lingbao != null) {
                        ZhuFrame.getZhuJpanel().creatlingtext(lingbao);
                        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE12);
                    }
                }
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
            if (type == -2) {
                ZhuFrame.getZhuJpanel().clearlingtext();
            } else if (type == -1) {
                ZhuFrame.getZhuJpanel().cleargoodtext();
            } else {
                if (p < 8) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                } else if (p < 10) {
                    ZhuFrame.getZhuJpanel().pettext();
                } else if (p < 12) {
                    ZhuFrame.getZhuJpanel().clearlingtext();
                }
            }
        }
    }

    class transPetMouse implements MouseListener {
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (myTransRole.goodTrans.getPets() != null && myTransRole.goodTrans.getPets().size() >= 2) {
                ZhuFrame.getZhuJpanel().addPrompt2("格子已满");
                return;
            }
            if (myTransRole.type != 0) {
                ZhuFrame.getZhuJpanel().addPrompt2("你已锁定");
                return;
            }
            if (UserMessUntil.getPetListTable().size() != 0) {// 有
                RoleSummoning pet = UserMessUntil.getPetListTable().get(listpet.getSelectedIndex());
                // 先判断召唤兽是否可交易
                if(pet.getQuality()!=null) {
                	if (!"2".equals(pet.getQuality())) {
                		ZhuFrame.getZhuJpanel().addPrompt("#R提示：#Y召唤兽#G【" + pet.getSummoningname() + "】#Y禁止交易！！！");
                		return;
                	}
                }
                // 先判断召唤兽是否有加锁
                if (pet.getPetlock() == 1) {
                    ZhuFrame.getZhuJpanel().addPrompt("#R提示：#Y召唤兽#G" + pet.getSummoningname() + "】#Y已被加锁，不可摆摊！！");
                    return;
                }
                // 先判断是否有参战的召唤兽
                if (RoleData.getRoleData().getLoginResult().getSummoning_id() != null) {// 有
                    if (pet.getSid().compareTo(RoleData.getRoleData().getLoginResult().getSummoning_id()) == 0) {
                        // 提示信息
                        ZhuFrame.getZhuJpanel().addPrompt2("#R提示：#Y该召唤兽在参战中，不可摆摊！");
                        return;
                    }
                }
                if (ZhuJpanel.getPetMount(pet.getSid()) != null) {
                    ZhuFrame.getZhuJpanel().addPrompt2("#R提示：#Y这只召唤兽被管制中，不可摆摊！！！");
                    return;
                }
                UserMessUntil.getPetListTable().remove(pet);
                listModel.remove(listpet.getSelectedIndex());
                myTransRole.goodTrans.setPet(pet, true);
                GoodTrans2 goodTrans2 = new GoodTrans2();
                goodTrans2.setI(true);
                goodTrans2.setPet(pet);
                String send = Agreement.getAgreement().TransGoodAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
                SendMessageUntil.toServer(send);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    }

    ImageIcon icon;
    ImageIcon icon2;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        	// 交易(左)
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B314.png");
            }
            g.drawImage(icon.getImage(), 0, 0, this);
            if (jpanelType == 1) {
                if (icon2 == null) {
                    icon2 = new ImageIcon("inkImg/newbackground/B315.png");
                }
                g.drawImage(icon2.getImage(), 23 + 24, 45 - 13, this);
            }
            // 画物品的图片和数量
            GoodsListFromServerUntil.draw(g, 217, 34);
            Util.drawMoney(g, 86, 221 + 13);
            g.setFont(UIUtils.TEXT_NAME_FONT);
            if (myTransRole != null) {
                myTransRole.paint(g);
                if (jpanelType == 1) {
                    RoleLingFa.getRoleLingFa().drawTrans(g, 51, 35, ys, myTransRole.goodTrans.getLingbaos());
                }
            }
            if (noTransRole != null) {
                noTransRole.paint(g);
            }
    }

    @Override
    public void upNum() {
        BigDecimal j1 = ((NumberDocument) myTransRole.field.getDocument()).getNum();
        BigDecimal j2 = myTransRole.goodTrans.getMoney();
        if (j2 == null) {
            j2 = new BigDecimal(0);
        }
        if (j1.compareTo(j2) != 0) {
            myTransRole.goodTrans.setMoney(j1);
            GoodTrans2 goodTrans2 = new GoodTrans2();
            goodTrans2.setI(true);
            goodTrans2.setMoney(j1);
            String send = Agreement.getAgreement().TransGoodAgreement(
                    GsonUtil.getGsonUtil().getgson().toJson(goodTrans2));
            SendMessageUntil.toServer(send);
        }
    }

    @Override
    public boolean isChange() {
        if (myTransRole == null) {
            return true;
        }
        return myTransRole.type != 0;
    }

    /** 刷新物品 */
    public void changTransGood(GoodTrans2 goodTrans2) {
        noTransRole.goodTrans.updateGood(goodTrans2);
        if (goodTrans2.getMoney() != null) {
            ((NumberDocument) noTransRole.field.getDocument()).replace(goodTrans2.getMoney().toString());
        }
    }

    /** 关闭交易 true 交易成功 物品扣除 false 交易失败 物品放回 */
    public void transClose(boolean is) {
        if (myTransRole == null || myTransRole.goodTrans == null) {
            return;
        }
        if (is) {
            if (myTransRole.goodTrans.getLingbaos() != null && myTransRole.goodTrans.getLingbaos().size() != 0) {
                RoleLingFa.getRoleLingFa().deleteling(myTransRole.goodTrans.getLingbaos());
            }
            if (FormsManagement.getframe(6).isVisible()) {
                UserMessUntil.setChosePetMes(null);
                PetPanelShow.Show();
            }
        } else {
            if (myTransRole.goodTrans.getGoods() != null && myTransRole.goodTrans.getGoods().size() != 0) {
                for (int i = 0; i < myTransRole.goodTrans.getGoods().size(); i++) {
                    Goodstable goodstable = myTransRole.goodTrans.getGoods().get(i);
                    GoodsListFromServerUntil.stall2(goodstable);
                }
            }
            if (myTransRole.goodTrans.getPets() != null && myTransRole.goodTrans.getPets().size() != 0) {
                for (int i = 0; i < myTransRole.goodTrans.getPets().size(); i++) {
                    RoleSummoning pet = myTransRole.goodTrans.getPets().get(i);
                    UserMessUntil.getPetListTable().add(pet);
                }
            }
        }
        myTransRole.goodTrans = null;
    }

    /** 状态更改 */
    public void CState(int zhi, String roleName) {
        // 锁定3 取消锁定4 确定5
        transRole role1 = null;
        transRole role2 = null;
        if (noTransRole.roleName.equals(roleName)) {
            role1 = noTransRole;
            role2 = myTransRole;
        } else if (RoleData.getRoleData().getLoginResult().getRolename().equals(roleName)) {
            role1 = myTransRole;
            role2 = noTransRole;
        }
        if (zhi == 3) {
            role1.setType(1);
        } else if (zhi == 4) {
            role1.setType(0);
            if (role2.type == 2) {
                role2.setType(1);
            }
        } else if (zhi == 5) {
            role1.setType(2);
        }
    }

    /** 确定 */
    public void queDing() {
        if (myTransRole.type == 0 || noTransRole.type == 0) {
            ZhuFrame.getZhuJpanel().addPrompt2("双方都锁定才能点击确定");
            return;
        }
        if (noTransRole.goodTrans.getGoods() != null) {
            int size = GoodsListFromServerUntil.Surplussum("-1", "-1", 999);
            if (size < noTransRole.goodTrans.getGoods().size()) {
                ZhuFrame.getZhuJpanel().addPrompt2("背包不足");
                return;
            }
        }
        if (noTransRole.goodTrans.getPets() != null) {
            int size = noTransRole.goodTrans.getPets().size() + UserMessUntil.getPetListTable().size();
            if (size >= 30) {
                ZhuFrame.getZhuJpanel().addPrompt2("召唤兽格子不足");
                return;
            }
        }
        //清空信息
        PetAddPointOneMouslisten.clearWindow();
        UserMessUntil.unsetChosePetMes();
        String send = Agreement.getAgreement().TransStateAgreement("5");
        SendMessageUntil.toServer(send);
    }

    public goodbtn[] getBtnrights() {
        return btnrights;
    }

    public void setBtnrights(goodbtn[] btnrights) {
        this.btnrights = btnrights;
    }

    public GoodTrans getGoodTrans() {
        if (myTransRole != null) {
            return myTransRole.goodTrans;
        }
        return null;
    }
}
